import * as Constant from '../utils/constant'
/**
 * 分页的mixins
 */
let Pagination = {
  data () {
    return {
      multipleSelection: [],
      pagingPageSizes: Constant.VUE_PAGING_DEFAULT_PAGESIZES,
      pagingTotal: 0, // 分页总数
      pageCount: 0, // 总页数
      pagingPageSize: Constant.VUE_PAGING_DEFAULT_PAGESIZE, // 分页的每页显示条数，注意：经过测试，虽然该值映射到的分页插件中，但是不会双向绑定。
      pagingCurrentPageNum: 1, // 分页当前选择的页数
      firstPageDisabled: true,
      lastPageDisabled: true
    }
  },
  created () {
  },
  methods: {
    indexMethod(index) {
      return (this.pagingCurrentPageNum-1)*this.pagingPageSize+index+1;
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    pagingHandleCurrentChange (currentPage) {
      this.pagingCurrentPageNum = currentPage
      this.getAllDataTable()
    },
    pagingHandleSizeChange (pageSize) {
      this.pagingCurrentPageNum = 1
      this.pagingPageSize = pageSize
      this.getAllDataTable()
    },
    firstPage () {
      this.pagingHandleCurrentChange(1)
    },
    lastPage () {
      this.pagingHandleCurrentChange(this.pageCount)
    },
    setPagingTotal (totalRecordSet) {
      this.pagingTotal = totalRecordSet
      let lastNum = this.pagingTotal / this.pagingPageSize
      let lastPage = Math.ceil(lastNum)
      this.pageCount = lastPage
      if (this.pagingCurrentPageNum === 1) {
        this.firstPageDisabled = true
      } else {
        this.firstPageDisabled = false
      }
      if (lastPage === this.pagingCurrentPageNum || lastPage === 0) {
        this.lastPageDisabled = true
      } else {
        this.lastPageDisabled = false
      }
    }
  },
  computed: {
  }
}
export default Pagination
